package cn.mazexal.examapi.models.vo;

import cn.mazexal.examapi.models.enums.MenuTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;


import java.io.Serializable;
import java.util.List;

/**
 * 卡片菜单，多重嵌套
 */
@Data
@Schema(description = "")
public class CardMenuVO implements Serializable {

    /**
     *
     */
    @Schema(description = "")
    private Long id;

    /**
     *
     */
    @Schema(description = "父ID")
    private Long parentId;

    /**
     *
     */
    @Schema(description = "")
    private String name;

    /**
     * 类型1，文件夹，2，选项
     */
    @Schema(description = "类型1，文件夹，2，选项")
    private Integer menuType;

    /**
     *
     */
    @Schema(description = "")
    private Long examBankId;

    @Schema(description = "排序值")
    private Integer sortNum;

    @Schema(description = "路径")
    private String path;

    @Schema(description = "子菜单列表")
    private List<CardMenuVO> children;

    @Schema(description = "统计题目,只有在错题和收藏返回")
    private Integer cnt;

    private boolean hasCalc = false;

    @Schema(description = "题目类型")
    private Integer questionType;


    public Integer getCnt() {
        if (hasCalc) {
            return cnt;
        }
        if (cnt == null) {
            hasCalc = true;
            return 0;
        }
        if (menuType == MenuTypeEnum.FOLDER.getCode()) {
            if (CollectionUtils.isNotEmpty(children)) {
                for (CardMenuVO child : children) {
                    cnt += child.getCnt();
                }
            } else {
                cnt = 0;
            }
        }
        hasCalc = true;
        return cnt;
    }
}